<?php
class TablesModel extends ModelSchema
{
    protected static $instance;

    public static function GetInstance()
    {
        if (is_null(self::$instance)) self::$instance = new TablesModel();
        return self::$instance;
    }

    protected function LoadFields()
    {
        parent::LoadFields();
        $this->SetForeignKey('TABLE_SCHEMA', 'SCHEMATA', 'SCHEMA_NAME');
        $this->SetForeignKey('ENGINE', 'ENGINES', 'ENGINE');
        $this->SetForeignKey('TABLE_COLLATION', 'COLLATIONS', 'COLLATION_NAME');
    }

    public function GetNameBySchema($schema = null)
    {
        $items = $this->GetBySchema($schema, 'TABLE_NAME');
        return Set::Pluck($items, 'TABLE_NAME');
    }

    public function GetBySchema($schema = null, $fields = null)
    {
        if (!$schema)
            $schema = ConnectionModel::GetInstance()->GetDefaultSchema();
        return $this->FindBy('TABLE_SCHEMA', $schema, $fields);
    }
}
?>
